package com.hspedu.encap;
/**
 * 创建程序,在其中定义两个类：Account和AccountTest类体会Java的封装性。
 * Account类要求具有属性：姓名（长度为2位3位或4位）、余额(必须>20)、
 * 密码（必须是六位）, 如果不满足，则给出提示信息，并给默认值(程序员自己定)
 * 通过setXxx的方法给Account 的属性赋值。
 * 在AccountTest中测试
 */
public class Account {
    private String name;
    private int balance;
    private int password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length()>=2 && name.length()<=4) {
            this.name = name;
        }else{
            System.out.println("姓名必须为长度为2位3位或4位");
        }
    }

    public int getBalance() {
        return balance;
    }

    public void setBalance(int balance) {
        if (balance>20){
            this.balance = balance;
        }else{
            System.out.println("余额必须大于20");
        }

    }

    public int getPassword() {
        return password;
    }

    public void setPassword(int password) {
        if (String.valueOf(password).length()==6){
            this.password = password;
        }else{
            System.out.println("密码必须为6位数");
        }

    }

    public Account() {
    }

    public Account(String name, int balance, int password) {
        this.name = name;
        this.balance = balance;
        this.password = password;
    }

    @Override
    public String toString() {
        return "Account{" +
                "name='" + name + '\'' +
                ", balance=" + balance +
                ", password=" + password +
                '}';
    }
}
